package chapter04

import org.apache.spark.sql.{DataFrame, Dataset, SparkSession}

object DataSetAPIApp {

  case class Person(name: String, age: String)

  def main(args: Array[String]): Unit = {

    val spark: SparkSession = SparkSession.builder()
      .appName("DataFrameAPIApp")
      .master("local")
      .getOrCreate()

    import spark.implicits._

    val ds: Dataset[Person] = Seq(Person("PK", "30")).toDS()
    //    ds.show()

    val primitiveDS: Dataset[Int] = Seq(1, 2, 3).toDS()
    // primitiveDS.map(x=>x+1).collect().foreach(println)

    val peopleDF: DataFrame = spark.read.json("file:///D:\\JAVApros\\spark_pk\\data\\people.json")
    val peopleDS: Dataset[Person] = peopleDF.as[Person]
    // peopleDS.show(false)

    //运行期报错
    // peopleDF.select("naem").show()
    peopleDS.map(x => x.name).show() //编译器报错


    spark.stop()


  }

}
